#!/bin/bash

source ./config.sh

APP_t=$1
APP_t2=${APP_t##*/}
ENERGY=$2
INPUT_SAMPLE=$3
INPUT_BFIELD=$4
EVENT=$5

INPUT_FILE_NAME=${INPUT_FILE_DIR}/${APP_t2}_${ENERGY}GeV_${INPUT_SAMPLE}_${INPUT_BFIELD}.in

if [ $ENERGY -gt 1000 ]; then
  GENERATOR=PYTHIA
else
  GENERATOR=particleGun
fi

if [ ${INPUT_SAMPLE} = antiproton ]; then
  INPUT_SAMPLE=anti_proton
fi

case $APP_t2 in
  ParN02 ) 
    echo "/run/verbose 1"  >  $INPUT_FILE_NAME 
    echo "/gun/particle " $INPUT_SAMPLE  >>  $INPUT_FILE_NAME 
    echo "/gun/energy " $ENERGY "Gev"  >>  $INPUT_FILE_NAME 
    echo "/N02/det/setField " $INPUT_BF " tesla" >>  $INPUT_FILE_NAME
    echo "/run/beamOn " 1000  >>  $INPUT_FILE_NAME 
    ;; 
  ParN03 ) 
    echo "/run/verbose 1"  >  $INPUT_FILE_NAME
    echo "/gun/particle " $INPUT_SAMPLE  >>  $INPUT_FILE_NAME
    echo "/gun/energy " $ENERGY "Gev"  >>  $INPUT_FILE_NAME
    echo "/N03/det/setField " $INPUT_BF " tesla" >>  $INPUT_FILE_NAME
    echo "/run/beamOn " 1000  >>  $INPUT_FILE_NAME
    ;;
  SimplifiedCalo ) 
    cat > $INPUT_FILE_NAME <<EOF
/run/verbose 1
/event/verbose 0
/tracking/verbose 0
/mygen/generator $GENERATOR
/gun/particle $INPUT_SAMPLE
/gun/energy   ${ENERGY} GeV
/mydet/setField $INPUT_BFIELD tesla
/mydet/absorberMaterial Copper
/mydet/activeMaterial Scintillator
/mydet/isCalHomogeneous 0
/mydet/isUnitInLambda 0
/mydet/absorberTotalLength 7000
/mydet/calorimeterRadius 3000
/mydet/activeLayerNumber 100
/mydet/readoutLayerNumber 20
/mydet/activeLayerSize 4.0
/mydet/radiusBinSize 0.1
/mydet/radiusBinNumber 10
/mydet/update
/run/beamOn $EVENT
EOF
    ;;

esac





